<?php

/**
 * @author HungPV <phamvanhung0818@gmail.com>
 * @todo manage projects controller
 */

class projects extends MX_Controller{
    function __construct() {
        parent::__construct();
        $this->load->model('project');
        $this->load->library('pagination');
        $this->load->model('category');
    }
    
    function index($cat = 'tat-ca', $row = 0) {
        //paging
        include('paging.php');
        $config['per_page'] = 12;
        $config['base_url'] = base_url() . "du-an/" . $cat . '/';

        if ($cat == 'tat-ca') {
            $lst_project = $this->project->get(-1, $config['per_page'], $row);
            $config['total_rows'] = $this->project->get_count();
        } else {
            $category = $this->category->get_by_permalink($cat);
            $data['category'] = $category;
            $cat_id = $category->id;
            $lst_project = $this->project->get(-1, $config['per_page'], $row, 'date', 'desc', $cat_id);
            $config['total_rows'] = $this->project->get_count($cat_id);
        }

        $config['cur_page'] = $row;
        $this->pagination->initialize($config);
        $data['list_link'] = $this->pagination->create_links();
        //data tranfer        
        $data['lst_project'] = $lst_project;

        $data['content'] = 'projects_index';
        $this->load->view('template/template', $data);
    }
    
    function detail($permalink){
        $project = $this->project->get_by_permalink($permalink);
        $data['project'] = $project;
        
        $data['content'] = 'projects_detail';
        $this->load->view('template/template', $data);
    }
    
    function footer(){
        $news_arr = $this->project->get(-1, 9, 0);
        $data['projects'] = $news_arr;
        $this->load->view('projects_footer', $data);
    }
    
    function recent(){
        $news_arr = $this->project->get(-1, 5, 0);
        $data['projects'] = $news_arr;
        $this->load->view('projects_recent', $data);
    }
}
?>
